<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/21
 * Time: 16:38
 */
require_once ('dbconn.php');
class UserDao{
    public function insert($account,$psw){
        //添加管理员
        $sql = "insert into user(user_account,user_psw) values ('" . $account . "','" . $psw . "')";
        //echo $sql;
        $conn = new dbconn();
        $link = $conn->connection();
        $query = mysqli_query($link, $sql);
        return $query;
    }

    //删除管理员
    public function delete($userId){
        $sql = "delete from user where user_id =".$userId;
        $conn = new dbconn();
        $link = $conn->connection();
        $query = mysqli_query($link,$sql) ;
        return $query;
    }

    //查询是否有此账号，或者通过账号查询id
    public function selectAccount($account){
        $sql = "select user_id from user where user_account='".$account."'";
        $conn = new dbconn();
        $link = $conn->connection();
        $query = mysqli_query($link,$sql) ;
        return $query;
    }

    //查询所有管理员账号和权限
    public function selectAll(){
        $sql = "select user_id,user_account,user_rant from user";
        $conn = new dbconn();
        $link = $conn->connection();
        $query = mysqli_query($link,$sql) ;
        return $query;
    }

    //根据账号查询密码
    public function selectPsw($account){
        $sql = "select user_psw from user where user_account='".$account."'";
        $conn = new dbconn();
        $link = $conn->connection();
        $query = mysqli_query($link,$sql) ;
        return $query;
    }

    public function updatePsw($account,$psw){
        $sql = "update user set user_psw = '".$psw."' where user_account='".$account."'";
        $conn = new dbconn();
        $link = $conn->connection();
        $query = mysqli_query($link,$sql) ;
        return $query;
    }
}